import { IFeidaoAiNodejsComponent } from '@feidao/web/interfaces';
import render from '@feidao/web/atom/nodejs/render/render';

// import get_menus from '@feidao/web/atom/nodejs/authorization/get-menus';
// import get_params from '@feidao/web/atom/nodejs/authorization/get-params';

import storage_set from '@feidao/web/atom/nodejs/storage/put';

function render_data(data: any[], p_name: string) {
	let res = '';
	function get_first_a(menu_name: string, icon: string) {
		return '<div class="ht30 l-ht30 bg-theme text-c radius-4 color-f font14 pos-r" style="width: 200px;">' + menu_name + '<i class="iconfont icon-quanyou font14 pos-a" style="right: 10px;"></i></div>';
	}
	function get_li(menu_name: string, package_url: string) {
		let h = ' href="' + package_url + '"';
		if (!package_url || package_url === 'undefined' || package_url === 'null') {
			h = ' style="cursor:default"';
		}
		return '<div class="left_li"><a style="color: blue;" ' + h + '><i class="iconfont icon-quanyou font12" style="margin:0 5px 0 15px;"></i>' + menu_name + '</a>';
	}
	let p_m = '';
	const pas = {};
	const check = {};
	const len = {};
	select_data("");
	if (pas[p_m] === 0) {
		res = res + '</div>';
	} else {
		res = res + '</div></div>';
	}

	function select_data(parent_no: string) {
		data.forEach((item) => {
			const menu_no = item.menu_no;
			const _parent_no = item.parent_no;
			const menu_name = item.menu_name;
			const package_url = item.package_url;
			const icon = item.icon;
			const is_show = item.is_show;
			if (is_show && (parent_no === _parent_no)) {
				const p_f_d = filter_data(menu_no);
				if (parent_no === "") {
					if (pas[p_m]) {
						if (pas[p_m] === 0) {
							res = res + '</div>';
						} else {
							res = res + '</div></div>';
						}
					} else {
						pas[menu_no] = p_f_d.length;
					}
					p_m = menu_no;
					res = res + get_first_a(menu_name, icon);
				} else {
					if (!check[_parent_no]) {
						check[_parent_no] = 1;
					} else {
						check[_parent_no] = check[_parent_no] + 1;
					}
					res = res + get_li(menu_name, package_url);
				}
				if (p_f_d.length > 0) {
					res = res + '<div class="text-l font14" style="width: 200px;margin:10px 0;">';
				} else {
					res = res + '</div>';
					len[_parent_no] = filter_data(_parent_no).length;
					if (len[_parent_no] === check[_parent_no]) {
						res = res + '</div></div>';
					}
				}
				select_data(menu_no);
			}
		});
	}

	function filter_data(p_no: string) {
		const filter = data.filter((item) => {
			const _parent_no = item.parent_no;
			return item.is_show && (_parent_no === p_no);
		});
		return filter;
	}
	const obj = {};
	obj[p_name] = res;
	return obj;
}

export default async function na001(fd: IFeidaoAiNodejsComponent, ...args: any[]) {
	// const menus = await get_menus(fd.data.msg, fd.data.headers);
	// console.warn(menus);

	const menus = [{
		"menu_no": "P070004000",
		"menu_name": "首页",
		"parent_no": "",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "index.html"
	}, {
		"menu_no": "P070004001",
		"menu_name": "控件",
		"parent_no": "",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": ""
	}, {
		"menu_no": "P070004001001",
		"menu_name": "WEB+H5",
		"parent_no": "P070004001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": ""
	}, {
		"menu_no": "P070004001001001",
		"menu_name": "轮播图",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000000.html"
	}, {
		"menu_no": "P070004001001002",
		"menu_name": "珊格-容器(1190)",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000001.html"
	}, {
		"menu_no": "P070004001001003",
		"menu_name": "珊格-行",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000002.html"
	}, {
		"menu_no": "P070004001001004",
		"menu_name": "珊格-容器(100%)",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000003.html"
	}, {
		"menu_no": "P070004001001005",
		"menu_name": "饼图",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000005.html"
	}, {
		"menu_no": "P070004001001006",
		"menu_name": "柱状图&折线图",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000006.html"
	}, {
		"menu_no": "P070004001001007",
		"menu_name": "折线图",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000007.html"
	}, {
		"menu_no": "P070004001001008",
		"menu_name": "柱状图",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000008.html"
	}, {
		"menu_no": "P070004001001009",
		"menu_name": "甘特图",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000009.html"
	}, {
		"menu_no": "P070004001001010",
		"menu_name": "开关按钮",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000010.html"
	}, {
		"menu_no": "P070004001001011",
		"menu_name": "环状图",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000011.html"
	}, {
		"menu_no": "P070004001001012",
		"menu_name": "评分",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000012.html"
	}, {
		"menu_no": "P070004001001013",
		"menu_name": "弹窗",
		"parent_no": "P070004001001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "wh000013.html"
	}, {
		"menu_no": "P070004001002",
		"menu_name": "WEB控件",
		"parent_no": "P070004001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": ""
	}, {
		"menu_no": "P070004001002001",
		"menu_name": "折叠树",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000001.html"
	}, {
		"menu_no": "P070004001002002",
		"menu_name": "百度地图v3.0",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000002.html"
	}, {
		"menu_no": "P070004001002003",
		"menu_name": "日历控件",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000004.html"
	}, {
		"menu_no": "P070004001002004",
		"menu_name": "下拉多选框",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000005.html"
	}, {
		"menu_no": "P070004001002005",
		"menu_name": "日期选择",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000006.html"
	}, {
		"menu_no": "P070004001002006",
		"menu_name": "文件上传",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000007.html"
	}, {
		"menu_no": "P070004001002007",
		"menu_name": "时间选择",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000008.html"
	}, {
		"menu_no": "P070004001002008",
		"menu_name": "a标签分页",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000009.html"
	}, {
		"menu_no": "P070004001002009",
		"menu_name": "按钮分页",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000010.html"
	}, {
		"menu_no": "P070004001002010",
		"menu_name": "珊格-列",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000011.html"
	}, {
		"menu_no": "P070004001002011",
		"menu_name": "相对于浏览器窗口定位的盒子",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000012.html"
	}, {
		"menu_no": "P070004001002012",
		"menu_name": "富文本框",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000013.html"
	}, {
		"menu_no": "P070004001002013",
		"menu_name": "天气预报",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000014.html"
	}, {
		"menu_no": "P070004001002014",
		"menu_name": "百度地图v2.0",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000015.html"
	}, {
		"menu_no": "P070004001002015",
		"menu_name": "七牛云上传",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000016.html"
	}, {
		"menu_no": "P070004001002016",
		"menu_name": "商城放大镜",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000017.html"
	}, {
		"menu_no": "P070004001002017",
		"menu_name": "下拉搜索框",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000018.html"
	}, {
		"menu_no": "P070004001002018",
		"menu_name": "画板",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000019.html"
	}, {
		"menu_no": "P070004001002019",
		"menu_name": "倒计时",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000020.html"
	}, {
		"menu_no": "P070004001002020",
		"menu_name": "查看全部",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000021.html"
	}, {
		"menu_no": "P070004001002021",
		"menu_name": "轮播图",
		"parent_no": "P070004001002",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "w000022.html"
	}, {
		"menu_no": "P070004001003",
		"menu_name": "H5控件",
		"parent_no": "P070004001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": ""
	}, {
		"menu_no": "P070004001003001",
		"menu_name": "划动列表",
		"parent_no": "P070004001003",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "h000000.html"
	}, {
		"menu_no": "P070004001003002",
		"menu_name": "划动列表-简易版",
		"parent_no": "P070004001003",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "h000001.html"
	}, {
		"menu_no": "P070004001003003",
		"menu_name": "滑动选择器",
		"parent_no": "P070004001003",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "h000002.html"
	}, {
		"menu_no": "P070004001003004",
		"menu_name": "珊格-列",
		"parent_no": "P070004001003",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "h000003.html"
	}, {
		"menu_no": "P070004001003005",
		"menu_name": "列表左滑抽屉",
		"parent_no": "P070004001003",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "h000004.html"
	}, {
		"menu_no": "P070004001004",
		"menu_name": "IE控件",
		"parent_no": "P070004001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "ie.html"
	}, {
		"menu_no": "P070004002",
		"menu_name": "问题汇总",
		"parent_no": "",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "questions.html"
	}, {
		"menu_no": "P070004003",
		"menu_name": "登录",
		"parent_no": "",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": ""
	}, {
		"menu_no": "P070004003001",
		"menu_name": "WEB登录",
		"parent_no": "P070004003",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": ""
	}, {
		"menu_no": "P070004003001001",
		"menu_name": "WEB登录-1",
		"parent_no": "P070004003001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "login.html"
	}, {
		"menu_no": "P070004003001002",
		"menu_name": "WEB登录-2",
		"parent_no": "P070004003001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "login2.html"
	}, {
		"menu_no": "P070004003001003",
		"menu_name": "WEB登录-3",
		"parent_no": "P070004003001",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "login3.html"
	}, {
		"menu_no": "P070004003002",
		"menu_name": "H5登录",
		"parent_no": "P070004003",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "h5-login.html"
	}, {
		"menu_no": "P070004004",
		"menu_name": "注册",
		"parent_no": "",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "register.html"
	}, {
		"menu_no": "P070004005",
		"menu_name": "导出",
		"parent_no": "",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "export.html"
	}, {
		"menu_no": "P070004006",
		"menu_name": "验证码",
		"parent_no": "",
		"icon": "icon-menu1",
		"priority": 1,
		"is_show": true,
		"background": "",
		"package_url": "captcha.html"
	}];
	await storage_set('menus', menus, "enroll-sys");

	// tslint:disable-next-line:no-string-literal
	render(fd.data.node, menus, render_data(menus, 'P01')['P01'], 'P01');

}
